using System;
using System.Collections.Generic;
using System.IO;
using Common;

namespace SProject.Program
{
	[Serializable]
	public class Step
	{
		public string Name { get; set; }

		public double Temperature { get; set; }

		public int HoldMinute { get; set; }

		public int HoldSecond { get; set; }

		public bool IsAcquisition { get; set; }

		public bool IsAdvProgram { get; set; }

		public int StartCycle { get; set; }

		public bool IsTempVarUp { get; set; }

		public double TempVarValue { get; set; }

		public bool IsTimeVarUp { get; set; }

		public int TimeVarValue { get; set; }

		public bool IsUseRamp { get; set; }

		public double Ramp { get; set; }

		public Step()
		{
			Temperature = 95.0;
			HoldMinute = 0;
			HoldSecond = 20;
			IsAcquisition = false;
			IsAdvProgram = false;
			IsTempVarUp = false;
			TempVarValue = 0.0;
			IsTimeVarUp = false;
			TimeVarValue = 0;
			IsUseRamp = false;
			Ramp = 0.0;
		}

		public void Copy(Step step)
		{
			if (step != null)
			{
				Name = step.Name;
				Temperature = step.Temperature;
				HoldMinute = step.HoldMinute;
				HoldSecond = step.HoldSecond;
				IsAcquisition = step.IsAcquisition;
				IsAdvProgram = step.IsAdvProgram;
				StartCycle = step.StartCycle;
				IsTempVarUp = step.IsTempVarUp;
				TempVarValue = step.TempVarValue;
				IsTimeVarUp = step.IsTimeVarUp;
				TimeVarValue = step.TimeVarValue;
				IsUseRamp = step.IsUseRamp;
				Ramp = step.Ramp;
			}
		}

		public Step Clone()
		{
			Step step = new Step();
			step.Copy(this);
			return step;
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		public override bool Equals(object obj)
		{
			if (obj == null)
			{
				return false;
			}
			Step step = obj as Step;
			if (step == null)
			{
				return false;
			}
			if (base.Equals(step))
			{
				return true;
			}
			if (Temperature == step.Temperature && HoldMinute == step.HoldMinute && HoldSecond == step.HoldSecond && IsAcquisition == step.IsAcquisition && IsAdvProgram == step.IsAdvProgram && (!IsAdvProgram || (IsAdvProgram && StartCycle == step.StartCycle && IsTempVarUp == step.IsTempVarUp && TempVarValue == step.TempVarValue && IsTimeVarUp == step.IsTimeVarUp && TimeVarValue == step.TimeVarValue)) && IsUseRamp == step.IsUseRamp)
			{
				if (IsUseRamp)
				{
					if (IsUseRamp)
					{
						return Ramp == step.Ramp;
					}
					return false;
				}
				return true;
			}
			return false;
		}

		public void SaveToStream(StreamEx stream)
		{
			stream.Write(PropertyKey.Key_Step);
			List<PropertyKey> list = new List<PropertyKey>();
			List<byte[]> list2 = new List<byte[]>();
			if (!string.IsNullOrEmpty(Name))
			{
				list.Add(PropertyKey.Key_Name);
				list2.Add(BytesConverter.GetBytes(Name));
			}
			list.Add(PropertyKey.Key_Temperature);
			list2.Add(BytesConverter.GetBytes(Temperature));
			list.Add(PropertyKey.Key_HoldMinute);
			list2.Add(BytesConverter.GetBytes(HoldMinute));
			list.Add(PropertyKey.Key_HoldSecond);
			list2.Add(BytesConverter.GetBytes(HoldSecond));
			list.Add(PropertyKey.Key_IsAcquisition);
			list2.Add(BytesConverter.GetBytes(IsAcquisition));
			list.Add(PropertyKey.Key_IsAdvProgram);
			list2.Add(BytesConverter.GetBytes(IsAdvProgram));
			list.Add(PropertyKey.Key_StartCycle);
			list2.Add(BytesConverter.GetBytes(StartCycle));
			list.Add(PropertyKey.Key_IsTempVarUp);
			list2.Add(BytesConverter.GetBytes(IsTempVarUp));
			list.Add(PropertyKey.Key_TempVarValue);
			list2.Add(BytesConverter.GetBytes(TempVarValue));
			list.Add(PropertyKey.Key_IsTimeVarUp);
			list2.Add(BytesConverter.GetBytes(IsTimeVarUp));
			list.Add(PropertyKey.Key_TimeVarValue);
			list2.Add(BytesConverter.GetBytes(TimeVarValue));
			list.Add(PropertyKey.Key_IsUseRamp);
			list2.Add(BytesConverter.GetBytes(IsUseRamp));
			list.Add(PropertyKey.Key_Ramp);
			list2.Add(BytesConverter.GetBytes(Ramp));
			stream.Write(PropertyKey.Key_Index);
			stream.WriteIndex(list, list2);
			stream.Flush();
		}

		public bool ReadFromStream(StreamEx stream)
		{
			PropertyKey propertyKey = stream.ReadKey();
			if (propertyKey == PropertyKey.Key_Step)
			{
				propertyKey = stream.ReadKey();
				if (propertyKey == PropertyKey.Key_Index)
				{
					List<PropertyKey> keys;
					List<byte[]> dates;
					stream.ReadIndex(out keys, out dates);
					for (int i = 0; i < keys.Count; i++)
					{
						switch (keys[i])
						{
						case PropertyKey.Key_Name:
							Name = BytesConverter.BytesToString(dates[i]);
							break;
						case PropertyKey.Key_Temperature:
							Temperature = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_HoldMinute:
							HoldMinute = BytesConverter.BytesToInt(dates[i]);
							break;
						case PropertyKey.Key_HoldSecond:
							HoldSecond = BytesConverter.BytesToInt(dates[i]);
							break;
						case PropertyKey.Key_IsAcquisition:
							IsAcquisition = BytesConverter.BytesToBool(dates[i]);
							break;
						case PropertyKey.Key_IsAdvProgram:
							IsAdvProgram = BytesConverter.BytesToBool(dates[i]);
							break;
						case PropertyKey.Key_StartCycle:
							StartCycle = BytesConverter.BytesToInt(dates[i]);
							break;
						case PropertyKey.Key_IsTempVarUp:
							IsTempVarUp = BytesConverter.BytesToBool(dates[i]);
							break;
						case PropertyKey.Key_TempVarValue:
							TempVarValue = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_IsTimeVarUp:
							IsTimeVarUp = BytesConverter.BytesToBool(dates[i]);
							break;
						case PropertyKey.Key_TimeVarValue:
							TimeVarValue = BytesConverter.BytesToInt(dates[i]);
							break;
						case PropertyKey.Key_IsUseRamp:
							IsUseRamp = BytesConverter.BytesToBool(dates[i]);
							break;
						case PropertyKey.Key_Ramp:
							Ramp = BytesConverter.BytesToDouble(dates[i]);
							break;
						}
					}
					return true;
				}
				stream.Seek(-4L, SeekOrigin.Current);
				while (true)
				{
					switch (stream.ReadKey())
					{
					case PropertyKey.Key_Name:
						Name = stream.ReadString();
						break;
					case PropertyKey.Key_Temperature:
						Temperature = stream.ReadDouble();
						break;
					case PropertyKey.Key_HoldMinute:
						HoldMinute = stream.ReadInt();
						break;
					case PropertyKey.Key_HoldSecond:
						HoldSecond = stream.ReadInt();
						break;
					case PropertyKey.Key_IsAcquisition:
						IsAcquisition = stream.ReadBool();
						break;
					case PropertyKey.Key_IsAdvProgram:
						IsAdvProgram = stream.ReadBool();
						break;
					case PropertyKey.Key_StartCycle:
						StartCycle = stream.ReadInt();
						break;
					case PropertyKey.Key_IsTempVarUp:
						IsTempVarUp = stream.ReadBool();
						break;
					case PropertyKey.Key_TempVarValue:
						TempVarValue = stream.ReadDouble();
						break;
					case PropertyKey.Key_IsTimeVarUp:
						IsTimeVarUp = stream.ReadBool();
						break;
					case PropertyKey.Key_TimeVarValue:
						TimeVarValue = stream.ReadInt();
						break;
					case PropertyKey.Key_IsUseRamp:
						IsUseRamp = stream.ReadBool();
						break;
					case PropertyKey.Key_Ramp:
						Ramp = stream.ReadDouble();
						break;
					default:
						stream.Seek(-4L, SeekOrigin.Current);
						return true;
					}
				}
			}
			stream.Seek(-4L, SeekOrigin.Current);
			return false;
		}
	}
}
